<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<!--<form action="{url:'trade/upload'} ">-->

<form action="/index/trade/upload" enctype="multipart/form-data" method="post">
<!--<form action="http://localhost/{url:'trade/upload'} " enctype="multipart/form-data" method="post">-->
<!--<form action="http://localhost/index/trade/upload " enctype="multipart/form-data" method="post">-->
    <input name='image' type="file">
    <input type="submit">
</form>

<div class="layui-upload">
    <button class="layui-btn" id="test2" type="button">图片上传(可多张)</button>
    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;max-width: 770px;">
        预览图：
        <div class="layui-upload-list" id="demo2"></div>
    </blockquote>
</div>

</body>
<script>
    //upload的启用
    layui.use('upload', function() {
        var $ = layui.jquery,
            upload = layui.upload;

        //多图片上传
        var uploadInst =upload.render({
            elem: '#test2',
            url: '/index/trade/upload', //改成您自己的上传接口
            field:'image',
            multiple: true,
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" style="height: 50px;width: 50px;padding-right: 50px">')
                });
            },
            done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                console.log("成功啦！" + res  + upload);
            }
            , error: function () {
                //演示失败状态，并实现重传
                console.log("faild"  + upload);

            },
            });
    })

</script>

</html>